package com.base.study.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.base.commonlib.recy.BasicRecyViewHolder;
import com.base.commonlib.recy.HFSingleTypeRecyAdapter;
import com.base.study.R;
import com.base.study.bean.OnlineStudyTreeBean;
import com.base.study.bean.OnlineStydyFirstListBean;
import com.base.study.bean.StudyListMenuBean;

/**
 * Created by Administrator on 2020/2/13.
 */

public class MenuLeftAdapter extends HFSingleTypeRecyAdapter<OnlineStudyTreeBean,MenuLeftAdapter.ViewHolder> {

    Context mContext;
    private int selectedItem;

    public MenuLeftAdapter(int resId, Context mContext) {
        super(resId);
        this.mContext=mContext;
        selectedItem = 0;
    }

    @Override
    public ViewHolder buildViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }
    public void selectTaskListItem(int pos) {

        int previousItem = selectedItem;
        selectedItem = pos;
        notifyItemChanged(previousItem);
        notifyItemChanged(pos);

    }

    @Override
    public void bindDataToHolder(ViewHolder holder, OnlineStudyTreeBean bean, int position) {
        if (selectedItem == position) {
            holder.title.setText(bean.getName());
            holder.left_menu_bg.setBackgroundColor(Color.parseColor("#FFFFFF"));
            holder.lin_isChecked.setVisibility(View.VISIBLE);
        }else {
            holder.title.setText(bean.getName());
            holder.left_menu_bg.setBackgroundColor(Color.parseColor("#f8f8fa"));
            holder.lin_isChecked.setVisibility(View.INVISIBLE);
        }
    }

    public static class ViewHolder extends BasicRecyViewHolder {

        TextView title;
        RelativeLayout left_menu_bg;
        LinearLayout lin_isChecked;

        public ViewHolder(View itemView) {
            super(itemView);
            title=(TextView) itemView.findViewById(R.id.title);
            left_menu_bg=(RelativeLayout) itemView.findViewById(R.id.left_menu_bg);
            lin_isChecked=(LinearLayout) itemView.findViewById(R.id.lin_isChecked);
        }


    }
}
